<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 引入刚刚下载的 ECharts 文件 -->
    <!--    <script src="echarts.js"></script>-->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.5.0/echarts.min.js"></script>
    <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
    <style>
        body{
            background-color: pink;
        }
        .echarts-content{
            gap: 10px;
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
        }
        .charts-item{
            background-color: white;
        }
        .grid-container {
            display: grid;
            grid-template-columns: auto auto auto auto;
            background-color: white;
        }
    </style>
</head>
<body>
<div class="echarts-content">
    <div id="main" class="charts-item" style="width: 100%;height:400px;"></div>
    <div id="main2" class="charts-item" style="width:  100%;height:400px;"></div>
    <div  style="background-color: aquamarine">1335533</div>
    <div id="main3" class="grid-container" style="width: 100%;height:400px;"></div>
</div>

</body>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
    //页面准备完毕，开始请求数据，画图
    $(function (){
        $.ajax({
            url:"../php/sj.php",
            success: function (res){
                console.log(res);
                drawChart1(res.data.xData,res.data.yData);
            },
            error:function (){
                alert("请求失败");
            }
        });
        $.ajax({
            url:"../php/sex.php",
            success: function (res){
                drawChart2(res.data);
            },
            error:function (){
                alert("请求失败");
            }
        });
        $.ajax({
            url:"../php/salary.php",
            success: function (res){
                drawChart3(res.data.xAxis,res.data.yAxis);
            },
            error:function (){
                alert("请求失败");
            }
        });


    });
</script>
<script type="text/javascript">
    function drawChart1(xData,yData){
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '员工部门分布'
            },
            tooltip: {},
            legend: {
                data: ['部门人数']
            },
            xAxis: {
                data: xData
            },
            yAxis: {},
            series: [
                {
                    name: '部门',
                    type: 'bar',
                    data: yData
                }
            ]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
    //绘制饼图
    function drawChart2(data) {
        var myChart = echarts.init(document.getElementById('main2'));
        option = {
            title: {
                text: '员工性别比例',
                left: 'center'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                left: 'left'
            },
            series: [
                {
                    name: '性别',
                    type: 'pie',
                    radius: '50%',
                    data: data,
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        myChart.setOption(option);
    }
    //绘制折线图
    function drawChart3(xAxis,yAxis) {
        var myChart = echarts.init(document.getElementById('main3'));
        //绘制折线图
            option = {
                title: {
                    text: '员工薪资图',
                    textStyle:{
                        color:'red',
                    }
                },
                xAxis: {
                    type: 'category',
                    data: xAxis
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: yAxis,
                        type: 'line'
                    }
                ]
            };
            myChart.setOption(option);
        }

</script>
</html>